//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
// 			VisualNovelToolkit		     /_/_/_/_/_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe.	/_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
using UnityEngine;
using System.Collections;

namespace ViNoToolkit{

	/// <summary>
	/// Unity wrapper class.
	/// </summary>
	static public class UnityWrapper {

		static public Object LoadResource( string path ){
			Object res = Resources.Load( path );
			Resources.UnloadUnusedAssets();	
			return res;
		}

		static public void InstantiateAsGameObject( Object resource , string parentName ){
			GameObject parent = GameObject.Find( parentName );
			GameObject clone = GameObject.Instantiate( resource ) as GameObject;// , Vector3.zero , Quaternion.identity ) as GameObject;
			if( parent != null ){
				Transform tra = clone.transform;
				Vector3 originalPosition = tra.localPosition;
				Quaternion originalRotation = tra.localRotation;
				Vector3 originalScale = tra.localScale;

				clone.transform.parent = parent.transform;
				clone.transform.localPosition = originalPosition;
				clone.transform.localRotation = originalRotation;			
				clone.transform.localScale = originalScale;
				
			}
			ViNoGOExtensions.StripGameObjectName( clone , "(Clone)" , "" );
		}

		static public void BeginTransition(){
			if( ITransition.Instance != null ){
				ITransition.Instance.BeginTransition();
			}
			else{
				Debug.LogWarning( "ITransition Instance not found.");
			}
		}

		static public void EndTransition(){
		if( ITransition.Instance != null ){
			ITransition.Instance.EndTransition();
		}
			else{
				Debug.LogWarning( "ITransition Instance not found.");
			}
		}

		/// <summary>
		/// Set the Flag ON.
		/// </summary>
		/// <param name='vm'>
		/// Vm.
		/// </param>
		static public void SetFlagPlayingScenario( string flagName , bool t ){
			if( ScenarioNode.Instance != null && ScenarioNode.Instance.flagTable != null ){
				ScenarioNode.Instance.flagTable.SetFlagBy( flagName ,  t );
			}
		}

		// ------------- Audio --------------.

		static public void PlaySound( byte soundCategory , byte soundID){
			if( ISoundPlayer.Instance == null ){
				Debug.LogWarning( "There is no ViNoSoundPlayer in this Scene.");
				return;			
			}
			switch( soundCategory ){
				case 0:	ISoundPlayer.Instance.PlayMusic( soundID , ViNoConfig.prefsBgmVolume , 0f ); break;
				case 1:	ISoundPlayer.Instance.PlaySE( soundID , 	 ViNoConfig.prefsSeVolume , 0f ); break;
				case 2:	ISoundPlayer.Instance.PlayVoice( soundID , ViNoConfig.prefsVoiceVolume , 0f ); break;
			}
		}
	}
}
